package one.undefined.Listeners.Interactions;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.components.Button;

import java.awt.Color;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.concurrent.TimeUnit;

public class StatsCommand extends ListenerAdapter {
    @Override
    public void onSlashCommand(SlashCommandEvent event)
    {
        if(!event.getName().equals("stats")) return;
        JDA api = event.getJDA();

        RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();

        EmbedBuilder embed = new EmbedBuilder()
                .setAuthor("Информация о боте")
                .setDescription("Разработчик: **undefined032#6666**" +
                        "\nХостинг: **DigitalOcean**" +
                        "\nЛокация: :flag_ca: **Канада, Торонто**" +
                        "\nБиблиотека: **JDA v4.3.0**")
                .addField("Статистика",
                "```Серверов: " + api.getGuilds().size() +
                        "\nПользователей в кеше: " + api.getUsers().size() +
                        "\nПинг: " + api.getGatewayPing() +
                        "\nАптайм: " + TimeUnit.MILLISECONDS.toDays(rb.getUptime()) + " дней, " +
                        TimeUnit.MILLISECONDS.toHours(rb.getUptime()) + " часа (-ов), " +
                        TimeUnit.MILLISECONDS.toMinutes(rb.getUptime()) + " минут (-ы)```", true)
                .setColor(Color.decode("#A09AE7"));
                event.replyEmbeds(embed.build())
                .addActionRow(
                        Button.link("https://undefined032.one", "Сервер поддержки"),
                        Button.link("https://undefined032.one", "Добавить бота")
                )
                .queue();
    }
}
